<%@ page language="java"
    pageEncoding="UTF-8"%>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>购物车</title>
		<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css" type="text/css" />
		<script src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js" type="text/javascript"></script>
		<script src="${pageContext.request.contextPath}/js/bootstrap.min.js" type="text/javascript"></script>
		<!-- 引入自定义css文件 style.css -->
		<link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css" type="text/css" />
		<style>
			body {
				margin-top: 20px;
				margin: 0 auto;
			}
			
			.carousel-inner .item img {
				width: 100%;
				height: 300px;
			}
			
			.container .row div {
				/* position:relative;
	 float:left; */
			}
			
			font {
				color: #3164af;
				font-size: 18px;
				font-weight: normal;
				padding: 0 10px;
			}
		</style>
		<%--导入核心库--%>
		<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
	</head>

	<body>

		<%--静态包含--%>
		<%@include file="header.jsp"%>


		<div class="container">
			<div class="row">

				<%--HttpSession中cart信息空了--%>
				<c:if test="${ empty cart}">
					<h2>亲,空空如也~~~,请<a href="${pageContext.request.contextPath}/index">购物</a>></h2>
				</c:if>

				<c:if test="${not empty cart}">
					<div style="margin:0 auto; margin-top:10px;width:950px;">
						<strong style="font-size:16px;margin:5px 0;">购物车信息</strong>
						<table class="table table-bordered">
							<tbody>
							<tr class="warning">
								<th>图片</th>
								<th>商品</th>
								<th>价格</th>
								<th>数量</th>
								<th>小计</th>
								<th>操作</th>
							</tr>
								<%--遍历每一个购物车项
                                        el表达式 可以操作javaBean
                                        快速ognl对象图导航语言操作bean属性
                                        ${域中的属性名.实体的bean属性}  ---域对象.getAttribute("属性名").getXXX()
                                                            访问getXXX()方法

                                --%>
							<c:forEach items="${cart.cartItems}" var="bean"> <%--bean代表每一个购物车项--%>
								<tr class="active">
									<td width="60" width="40%">
										<input type="hidden" name="id" value="22">
										<img src="${pageContext.request.contextPath}/${bean.product.pimage}" width="70" height="60">
									</td>
									<td width="30%">
										<a target="_blank">${bean.product.pname}</a>
									</td>
									<td width="20%">
										￥${bean.product.shop_price}
									</td>
									<td width="10%">
										<input type="text"  value="${bean.count}" maxlength="4" size="10">
									</td>
									<td width="15%">
										<span class="subtotal">￥${bean.subTotal}</span>
									</td>
									<td>
										<a href="javascript:void(0)" onclick="delCartItem('${bean.product.pid}')" class="delete">删除</a>
									</td>
								</tr>
							</c:forEach>

							</tbody>
						</table>
					</div>
					<div style="margin-right:130px;">
						<div style="text-align:right;">
							<em style="color:#ff6600;">
								登录后确认是否享有优惠&nbsp;&nbsp;
							</em> 赠送积分: <em style="color:#ff6600;">${cart.totalMoney}</em>&nbsp; 商品金额: <strong style="color:#ff6600;">￥${cart.totalMoney}元</strong>
						</div>
				</c:if>

			</div>


				<div style="text-align:right;margin-top:10px;margin-bottom:10px;">
					<a href="${pageContext.request.contextPath}/cart?methodName=clareCart" id="clear" class="clear">清空购物车</a>
					<a href="${pageContext.request.contextPath}/order?methodName=generateOrder">
						<input type="submit" width="100" value="提交订单" name="submit" border="0" style="background-color:#E66B1A" />
					</a>
				</div>
			</div>

		</div>

		<!--
                        描述：页脚部分
                    -->
			<div class="container-fluid">

				<div style="float: left;margin-left: 30px;margin-top: 25px">
					<img src="${pageContext.request.contextPath}/image/logo-mi2.png" width="80px" height="80px">
				</div>
				<div style="text-align: center;margin-top: 5px;float: left;margin-left: 30px;margin-top: 50px;text-align: center" >
					<ul class="list-inline">
						<li><a href="info.html">小米商城</a></li>|
						<li><a>MIUI</a></li>|
						<li><a>米家</a></li>|
						<li><a>多看</a></li>|
						<li><a>游戏</a></li>|
						<li><a>政企服务</a></li>|
						<li><a>小米天猫店</a></li>|
						<li><a>小米集团隐私政策</a></li>|
						<li><a>小米公司儿童信息保护规则</a></li>|
						<li><a>米家隐私</a></li>|
						<li><a>问题反馈</a></li>|
						<li><a>招贤纳士</a></li>|
						<li><a>投诉建议</a></li>
					</ul>
				</div>
				<div style="clear: both"></div>
				<div  style="text-align: center;margin-top: 5px;margin-bottom:20px;">

					Copyright &copy;2020-2030  Rice mall
				</div>
			</div>

	</body>

<script>

		function delCartItem(pid){
			//alert(pid) ;
			//确认提示框
			var flag = window.confirm("您忍心删除吗?") ;
			if(flag){
				//向服务器发送请求
				window.location.href="${pageContext.request.contextPath}/cart?methodName=delCartItemFromCart&pid="+pid+"" ;
			}

		}
</script>

</html>